package com.ezscript.cvs;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;


/**
 * 改变cvs中的ROOT文件，是cvs指向其他服务
 * @author MaXin
 * 
 */
public class ChangeIP {

	//public static String fileName = "E:\\c#\\DHB5-DHB400-DHB100\\PortDHB5\\PortDHB5"; //文件夹名秄1�7
	/**
	 * 需要改变的文件夹
	 */
	public static String fileName ="E:\\c#\\monitor";
	/**
	 * 要改变成的ROOT值
	 */
	public static String ROOT=":pserver:maxin@192.168.10.239/DHY";

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		File folder = new File(fileName);
		System.out.println(folder.isDirectory());
		changeCVS(folder);
	}

	private static void changeCVS(File folder) {
		File[] files = folder.listFiles();
		for (int i = 0; i < files.length; i++) {
			if (files[i].isDirectory()) {
				if (files[i].getName().equals("CVS"))
					changeROOT(files[i]);
				else
					changeCVS(files[i]);
			}
		}
	}

	private static void changeROOT(File file){
		String fileName = file.getAbsolutePath() +"\\Root";
		writeToFile(fileName,ROOT);
	}
	
    /**
     * B方法追加文件：使用FileWriter
     */
    public static void writeToFile(String fileName, String content) {
        try {
            FileWriter writer = new FileWriter(fileName);
            writer.write(content);
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
	
}